
function CGame(oDataInfo) {
    var _pStartPosAudio;
    var _pStartPosInfo;
    var _oButPlay;
    var _oButInfo;
    var _oFade;
    var _oAudioToggle;
    var _oContainerStack;
    var _oBlackboard;
    var _btnpre;
    var _btnnxt;
    var _btnsetting;
    var _btnpredis;
    var _btnnxtdis;

    var _text;
    var _title;
    var _oPointer;

    var _curPage;
    var _maxPage;
    var _pageSize = 10;
    var _arrContent;

    this._init = function (oDataInfo) {
        _oContainerStack = new createjs.Container();
        s_oStage.addChild(_oContainerStack);

        _oBlackboard = createBitmap(s_oSpriteLibrary.getResult('blackboard'));
        _oContainerStack.addChild(_oBlackboard);

        _btnpre = createBitmap(s_oSpriteLibrary.getResult('pre'));
        _btnpre.x = 410;
        _btnpre.y = 5;
        _oContainerStack.addChild(_btnpre);
        _btnpre.on("mousedown", this.preButtonDown);
        _btnpre.on("pressup", this.preButtonRelease);

        _btnpredis = createBitmap(s_oSpriteLibrary.getResult('pre-dis'));
        _btnpredis.x = 410;
        _btnpredis.y = 5;
        _oContainerStack.addChild(_btnpredis);

        _btnnxt = createBitmap(s_oSpriteLibrary.getResult('next'));
        _btnnxt.x = 580;
        _btnnxt.y = 5;
        _oContainerStack.addChild(_btnnxt);
        _btnnxt.on("mousedown", this.nxtButtonDown);
        _btnnxt.on("pressup", this.nxtButtonRelease);
        _btnnxtdis = createBitmap(s_oSpriteLibrary.getResult('nxt-dis'));
        _btnnxtdis.x = 580;
        _btnnxtdis.y = 5;
        _oContainerStack.addChild(_btnnxtdis);

        _btnsetting = createBitmap(s_oSpriteLibrary.getResult('star'));
        _btnsetting.x = 780;
        _btnsetting.y = 5;
        _oContainerStack.addChild(_btnsetting);
        _btnsetting.on("mousedown", this.settingButtonDown);
        _btnsetting.on("pressup", this.settingButtonRelease);

        if (DISABLE_SOUND_MOBILE === false || s_bMobile === false) {
            var _btnshengyin = s_oSpriteLibrary.getResult('soundsprite');
            _pStartPosAudio = {x: CANVAS_WIDTH - (_btnshengyin.height / 2) - 15, y: (_btnshengyin.height / 2) + 15};
            _oAudioToggle = new CToggle(240, (_btnshengyin.height / 2) + 5, _btnshengyin, s_bAudioActive, _oContainerStack);
            _oAudioToggle.addEventListener(ON_MOUSE_UP, this._onAudioToggle, this);
        }

        var linenum = this._getLines(oDataInfo);
        _maxPage = Math.ceil(linenum / _pageSize);
        _curPage = 1;
        console.log(_maxPage + "--" + _curPage);
        _text = new CFormatText(0, 0, this._getTextByCurPage(), "#FFFFFF", _oContainerStack, "#FFFFFF", 36);

        this.setToolsStatus();
        // 整体宽度
        var w = _text.getWidth();
        console.log("width=" + _text.getWidth());
        w = (1024 - w) / 2 + 130;
        _text.setPosition(w, 120);
        console.log("w=" + w);
        _text.disableOutline();
        _text.setShadow(true);
        _title = new CFormatVerticalText(820, 100, oDataInfo.title, "#FFFFFF", _oContainerStack, "#FFFFFF", 36);
        _title.disableOutline();
        _title.setShadow(true);
        _oPointer = playSound(oDataInfo.sou, 1, 0);
    };

    /**
     * 设置菜单状态
     */
    this.setToolsStatus = function () {
        if (_curPage == 1) {
            _btnpre.visible = false;
            _btnpredis.visible = true;
        } else {
            _btnpre.visible = true;
            _btnpredis.visible = false;
        }
        if (_curPage == _maxPage) {
            _btnnxt.visible = false;
            _btnnxtdis.visible = true;
        } else {
            _btnnxt.visible = true;
            _btnnxtdis.visible = false;
        }
    };

    this.nxtButtonDown = function () {
        _btnnxt.scaleX = 0.9;
        _btnnxt.scaleY = 0.9;
    };
    this.nxtButtonRelease = function () {
        _btnnxt.scaleX = 1;
        _btnnxt.scaleY = 1;

        _curPage++;
        if (_curPage > _maxPage) {
            _curPage = _maxPage;
            s_oGame.setToolsStatus();
            return;
        }
        s_oGame.setToolsStatus();
        createjs.Tween.get(_text.getSelf(), {loop:false}, true)
            .to({alpha:0},1000,createjs.Ease.linear)
            .call(function () {
                _text.setText(s_oGame._getTextByCurPage());
                createjs.Tween.get(_text.getSelf(),{loop:false},true)
                    .to({alpha:1},1000,createjs.Ease.linear)
            });
    };

    this.preButtonDown = function () {
        _btnpre.scaleX = 0.9;
        _btnpre.scaleY = 0.9;
    };
    this.preButtonRelease = function () {
        _btnpre.scaleX = 1;
        _btnpre.scaleY = 1;

        _curPage--;
        if (_curPage < 1) {
            _curPage = 1;
            s_oGame.setToolsStatus();
            return;
        }
        s_oGame.setToolsStatus();
        createjs.Tween.get(_text.getSelf(), {loop:false}, true)
            .to({alpha:0},1000,createjs.Ease.linear)
            .call(function () {
                _text.setText(s_oGame._getTextByCurPage());
                createjs.Tween.get(_text.getSelf(),{loop:false},true)
                    .to({alpha:1},1000,createjs.Ease.linear)
            });
    };

    this.settingButtonDown = function () {
        _btnsetting.scaleX = 0.9;
        _btnsetting.scaleY = 0.9;
    };
    this.settingButtonRelease = function () {
        _btnsetting.scaleX = 1;
        _btnsetting.scaleY = 1;

        playSound("click", 1, 0);

        stopSound(_oPointer);
        _oContainerStack.removeAllChildren();

        s_oGame = null;
        // s_oMenu.setVisible(true);
        window.open("./home.html", "_self");
    };

    this._getLines = function (oDataInfo) {
        _arrContent = oDataInfo.content.split('\n');
        return _arrContent.length;
    };

    this._getTextByCurPage = function () {
        if (!_arrContent)
            return "";

        if (_curPage < 1)
            return "";

        var begin = (_curPage - 1) * _pageSize;
        var end = _curPage * _pageSize;
        if (_curPage >= _maxPage) {
            end = Math.max(_curPage * _pageSize, _arrContent.length);
        }
        var arrtext = _arrContent.slice(begin, end);
        return arrtext.join('\n');
    }

    this.setVisible = function (flag) {
        _oContainerStack.visible = flag;
    };

    this.refreshButtonPos = function (iNewX, iNewY) {
        _oButInfo.setPosition(_pStartPosInfo.x + iNewX, _pStartPosInfo.y + iNewY);

        if (DISABLE_SOUND_MOBILE === false || s_bMobile === false) {
            _oAudioToggle.setPosition(_pStartPosAudio.x - iNewX, iNewY + _pStartPosAudio.y);
        }
    };

    this.unload = function () {
        _oButPlay.unload();
        _oButPlay = null;

        _oButInfo.unload();
        _oButInfo = null;

        if (DISABLE_SOUND_MOBILE === false || s_bMobile === false) {
            _oAudioToggle.unload();
            _oAudioToggle = null;
        }

        s_oStage.removeAllChildren();

        s_oGame = null;
    };

    this._onAudioToggle = function () {
        createjs.Sound.setMute(s_bAudioActive);
        if (s_bAudioActive) {
            _oPointer.paused = true;
        } else {
            _oPointer.paused = false;
        }
        s_bAudioActive = !s_bAudioActive;
    };

    this._onButInfoRelease = function () {
        new CCreditsPanel();
    };

    this._onButPlayRelease = function () {        //       playSound("click", 1, 0);
        this.fadeAnim();
    };

    this.fadeAnim = function () {
        var oParent = this;
        _oFade.visible = true;
        createjs.Tween.get(_oFade, {override: true}).to({alpha: 1}, MS_FADE_ANIM, createjs.Ease.cubicIn).call(function () {
            oParent.unload();
            s_oMain.gotoGame();
        });
    };

    this.changeText = function(txt, title) {
        createjs.Tween.get(_text.getSelf(),{loop:false},true)
            .to({alpha:0},1000,createjs.Ease.linear)
            .call(function () {
                _text.setText(txt);
                createjs.Tween.get(_text.getSelf(),{loop:false},true)
                    .to({alpha:1},1000,createjs.Ease.linear)
            });

        createjs.Tween.get(_title.getSelf(),{loop:false},true)
            .to({alpha:0},1000,createjs.Ease.linear)
            .call(function () {
                _title.setText(title);
                createjs.Tween.get(_title.getSelf(),{loop:false},true)
                    .to({alpha:1},1000,createjs.Ease.linear)
            });
    };

    s_oGame = this;
    this._init(oDataInfo);
}

var s_oGame = null;